package com.sunlands.zlcx.usercenter.service.status;

import com.sunlands.zlcx.usercenter.constant.LearningStatus;
import com.sunlands.zlcx.usercenter.constant.RedisKeyConst;
import com.sunlands.zlcx.usercenter.domain.UsersStudyInfoDO;
import com.sunlands.zlcx.usercenter.domain.UsersTargetRelationDO;
import com.sunlands.zlcx.usercenter.service.status.common.AbstractStudyStatus;
import com.sunlands.zlcx.usercenter.util.BeanPropertiesUtil;
import com.sunlands.zlcx.usercenter.vo.UsersStudyInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutionException;

/**
 * @author gaoyanfeng
 * @create 2019-04-28 9:50
 **/
@Component
@Slf4j
public class JobStartLearn extends AbstractStudyStatus implements BeanPropertiesUtil {
    @Override
    public void handle(UsersStudyInfoVO studyInfo, UsersTargetRelationDO targetRelation) {

        Long userId = targetRelation.getUserId();
        studyInfo.setType(UsersStudyInfoDO.TypeEnums.ORDERNARY_COUNT_TIME_START.code);
        redisTemplate.opsForValue().set(RedisKeyConst.getStudyName(userId), studyInfo.getStudyInfoName());
        sendMessage(userId, "开始了学习");
        usersService.updateStatus(userId, LearningStatus.LEARN_TIMING.getCode(), studyInfo.getStartTime(), null, null);

    }
}
